package common;

public class Probability {
	private double logProb;

	public Probability() {
		logProb = Double.NEGATIVE_INFINITY;
	}

	public Probability(double prob) {
		setProbability(prob);
	}

	public int compareTo(Probability prob) {
		return Double.compare(logProb, ((Probability) prob).logProb);
	}

	public Probability multiply(Probability prob) {
		Probability result = new Probability();
		result.setLogProbability(logProb + prob.logProb);
		return result;
	}

	@Override
	public Object clone() {
		Probability p = new Probability();
		p.setLogProbability(logProb);
		return p;
	}

	public void setLogProbability(double newLogProb) {
		logProb = newLogProb;
	}

	public void setProbability(double prob) {
		logProb = Math.log(prob);
	}

}
